package asddqd;

import java.util.*;

public class Animal {
	int x;
	int y;

	void move() {
		Random rand = new Random();
		System.out.println("\t" + Mane());
		while (true) {
			x = rand.nextInt(9);
			y = rand.nextInt(9);
			if (x >= 0 && x < 8 && y >= 0 && y < 8) {
				System.out.println("当前坐标为 " + x + "," + y);
				return;
			} else {
				System.out.println("坐标为 " + x + "," + y + "      越界");
				System.out.println("重新生成坐标");
				continue;
			}
		}

	}

	void Features() {
	}

	String Mane() {
		return null;
	}

	void eat(Animal H[]) {

		for (int z = 0; z < H.length; z++) {
			for (int i = z + 1; i < H.length; i++) {
				if (H[0] != null && H[1] != null) {
					if (H[z].x == H[i].x && H[z].y == H[i].y) {
						System.out.println(H[z].Mane() + "被" + H[i].Mane() + "吃了");
						H[z] = null;
					}
				}
			}
		}

	}

	public static void main(String[] args) {
		Animal H[] = { new sheep("羊", 5, 5), new wolf("狼", 6, 6), new Tiger("老虎", 7, 7) };
		Animal a = new Animal();
		for (Animal A : H) {
			A.Features();
		}
		System.out.println("活动范围在0-8");
		for (int i = 1; i < 50; i++) {
			System.out.println("");
			System.out.println("第" + i + "回合");
			for(Animal A:H) {
				if (A != null) {
					A.move();
				}
			}
			a.eat(H);
		}
	}
}